// 请求模块
import axios from 'axios'
import store from '@/store'
const baseURL = 'http://toutiao.itheima.net'

const request = axios.create({
  baseURL,
  timeout: 5000
})
// 请求拦截器
request.interceptors.request.use(config => {
  const { user } = store.state
  if (user && user.token) {
    config.headers.Authorization = `Bearer ${user.token}`
  }
  return config
}, err => Promise.reject(err))
export default request
